home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MAIL.SWG / 0007_Reading MSG Header.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  4KB  |  132 lines

  1. { MARK LEWIS }
  2.  
  3. Uses
  4.   Dos;
  5.  
  6. Type
  7.   ti = Record
  8.     Var1 : Word;
  9.     Var2 : Word;
  10.   end;
  11.  
  12.   MsgInfo = Record
  13.     From_Name : Array[1..36] of Char;
  14.     To_Name   : Array[1..36] of Char;
  15.     Subject   : Array[1..72] of Char;
  16.     DateTime  : Array[1..20] of Char;
  17.     timesread : Word;
  18.     destnode  : Word;
  19.     orignode  : Word;
  20.     cost      : Word;
  21.     orignet   : Word;
  22.     destnet   : Word;
  23.     field1    : ti;    { these two have at least two seperate }
  24.     field2    : ti;    { Uses. time sent/rcvd or zone/point info }
  25.     replyto   : Word;
  26.     attribute : Word;
  27.     nextmsg   : Word;
  28.   end;
  29.  
  30. {
  31. ahhh... what the heck... the following will read the MSG header and display
  32. it... i'll leave the processing of the messagebody as an exercise For the
  33. reader(s)... it's a lot of fun... make sure you get/have the FTSC documents
  34. handy... there is one that talks about hints to follow when processing messages
  35. (in .PKT's and in .MSG's) like filtering out all CR's, LF's and softcarriage
  36. returns -=B-)
  37. }
  38.  
  39. Var
  40.   MInfo    : MsgInfo;
  41.   MSGName  : PathStr;
  42.   MSGFile  : File;
  43.   i        : Byte;
  44.   t1,t2    : datetime;
  45.   notdate  : Boolean;
  46.   numread  : Word;
  47.  
  48. {-------------------------------------------------------------------------}
  49. begin  { Main Body }
  50.   assign(output, '');
  51.   reWrite(output);
  52.   Filemode := 64;
  53.   MSGName  := ParamStr(1); { Get message Filename from command line }
  54.   if (MSGName = '') Then
  55.   begin
  56.     WriteLn('Name of *.MSG must be specified on command line.');
  57.     Halt;
  58.   end;
  59.   FillChar(Minfo,SizeOf(Minfo),#0);
  60.   Assign(MSGFile,MSGName);
  61.   {$I-} Reset(MSGFile,1); {$I+}
  62.   if IOResult <> 0 Then
  63.   begin
  64.     Writeln('Unable to open the *.MSG!');
  65.     halt;
  66.   end;
  67.   { Read in header... }
  68.   BlockRead(MSGFile,Minfo,SizeOf(Minfo),NumRead);
  69.   { decode time/date fields For FrontDoor/OPUS }
  70.   { i think this is a UNIX time/date format but not sure }
  71.   t1.min   := (minfo.field1.Var2 and $07e0) shr 5;
  72.   t1.hour  := (minfo.field1.Var2 and 63488) shr 11;
  73.   t1.sec   := 0;
  74.   t1.year  := 1980 + (minfo.field1.Var1 and $fe00) shr 9;
  75.   t1.month := (minfo.field1.Var1 and $01e0) shr 5;
  76.   t1.day   := (minfo.field1.Var1 and $001f);
  77.   t2.min   := (minfo.field2.Var2 and $07e0) shr 5;
  78.   t2.hour  := (minfo.field2.Var2 and 63488) shr 11;
  79.   t2.sec   := 0;
  80.   t2.year  := 1980 + (minfo.field2.Var1 and $fe00) shr 9;
  81.   t2.month := (minfo.field2.Var1 and $01e0) shr 5;
  82.   t2.day   := (minfo.field2.Var1 and $001f);
  83.   if (t1.year < 1990) and (t2.year < 1990) then
  84.     notdate := True
  85.   else
  86.     notdate := False;
  87.     { if the years are over three years ago, then we are probably }
  88.     { processing a message that is using these fields For their }
  89.     { other documented use. }
  90.   Write('From: ');
  91.   For i := 1 to 36 do
  92.     Write(minfo.from_name[i]);
  93.   Writeln;
  94.   Write('To  : ');
  95.   For i := 1 to 36 do
  96.     Write(minfo.to_name[i]);
  97.   Writeln;
  98.   Write('Subj: ');
  99.   For i := 1 to 72 do
  100.     Write(minfo.subject[i]);
  101.   Writeln;
  102.   Write('Date: ');
  103.   For i := 1 to 20 do
  104.     Write(minfo.datetime[i]);
  105.   Writeln;
  106.   Writeln('timesread : ',minfo.timesread);
  107.   Writeln(' destnode : ',minfo.destnode );
  108.   Writeln(' orignode : ',minfo.orignode );
  109.   Writeln('     cost : ',minfo.cost     );
  110.   Writeln('  orignet : ',minfo.orignet  );
  111.   Writeln('  destnet : ',minfo.destnet  );
  112.   if notdate then
  113.   begin
  114.     Writeln(' destzone : ',minfo.field1.Var1);
  115.     Writeln(' origzone : ',minfo.field1.Var2);
  116.     Writeln('destpoint : ',minfo.field2.Var1);
  117.     Writeln('origpoint : ',minfo.field2.Var2);
  118.   end
  119.   else
  120.   begin
  121.     Writeln('    time1 : ',t1.month,'/',t1.day,'/',t1.year,'   ',
  122.                            t1.hour,':',t1.min,':',t1.sec);
  123.     Writeln('    time2 : ',t2.month,'/',t2.day,'/',t2.year,'   ',
  124.                            t2.hour,':',t2.min,':',t2.sec);
  125.   end;
  126.   Writeln('  replyto : ',minfo.replyto  );
  127.   Writeln('attribute : ',minfo.attribute);
  128.   Writeln('  nextmsg : ',minfo.nextmsg  );
  129.   Close(MSGFile);
  130. end.
  131.  
  132.